
#include<stdlib.h>

#include<string.h>
#include"test_stdio.h"

#include<fcntl.h>
#include<sys/types.h>
#include<sys/stat.h>

#include<unistd.h>

MY_FILE *Fopen(const char* filename,const char* mode)
{
  int fd=-1;  //文件标识符、

  if(strcmp(mode,"r")==0)
  {  
      //如果相等 说明了是一样的
      fd=open(filename,O_RDONLY);

  }
  else if(strcmp(mode,"w")==0)
  {
      fd=open(filename,O_WRONLY|O_CREAT|O_TRUNC,0666);
  }
  else if(strcmp(mode,"a")==0)
  {
      fd=open(filename,O_APPEND|O_CREAT|O_WRONLY,0666);
  }

  if(fd<0)
  {
      return NULL;
  }

  MY_FILE* mf=(MY_FILE*)malloc(sizeof(MY_FILE));
  if(!mf)
  {
      //创建失败
      close(fd);
      return NULL;
      
  }


  mf->cap=SIZE;
  mf->FILENAME=fd;
  mf->FLAG=FLUSH_LINE;
  mf->size=0;

  

 return mf;
}





